require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsFriendApplyHandler={};
local this = RedDotsFriendApplyHandler;

function RedDotsFriendApplyHandler.init()
    CloseEvent(Config.EventType.Fresh_ApplyFriend,this.update);
    ListenEvent(Config.EventType.Fresh_ApplyFriend,this.update);
    return this;
end


--参数1：playerId，nil代表检查所有
function RedDotsFriendApplyHandler.getFlag(...)
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Friend,false) then
        local playerId = ...;
        local flag = Config.RedDotsFlagState.None;
        local list = logicMgr.FriendManager.GetFriendList(EnumConst.FriendType.applyFriend)
        if list~=nil then
            if playerId~= nil then
                for key, value in pairs(list) do
                    if value.playerId == playerId then
                        return Config.RedDotsFlagState.Needful;
                    end
                end
            else
                if  table.getn(list)> 0 then
                    return Config.RedDotsFlagState.Needful;
                end
            end
        end
    end
    return Config.RedDotsFlagState.None;
end


function RedDotsFriendApplyHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.FriendApply);
end